package com.itbaizhan.openhis.controller.sms;

import com.itbaizhan.openhis.service.VerificationCodeService;
import com.itbaizhan.openhis.vo.AjaxResult;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("system/sms")
public class SmsSendController {

    @Reference  //远程调用
    private VerificationCodeService verificationCodeService;

    /**
     *获取验证码
     * @param phoneNumber
     * @return
     * 通过@PathVariable可以将URL中占位符参数{xxx}绑定到处理器类的方法形参中
     * @RequestParam 和 @PathVariable 注解是用于从 request 中接收请求的，两个都可以接收参数，关键点不同的是@RequestParam 是从 request 里面拿取值，而 @PathVariable 是从一个URI模板里面来填充
     *
     */
    @PostMapping("sendSms/{phoneNumber}")
    public AjaxResult acquireVerifyCode(@PathVariable String phoneNumber){
        return AjaxResult.toAjax(verificationCodeService.sendSms(phoneNumber));
    }

    /**
     * 校验验证码
     * @param phoneNumber
     * @param code
     * @return
     */
    @GetMapping("checkCode/{phoneNumber}/{code}")
    public AjaxResult checkCode(@PathVariable String phoneNumber,@PathVariable Integer code){
        return AjaxResult.success(verificationCodeService.checkCode(phoneNumber,code));
    }
}
